<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>VPN管理系统登录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css">
    <link rel="stylesheet" href="/admin/css/login.css">
    <link rel="stylesheet" href="./js/layui/css/layui.css">
    <link rel="stylesheet" href="./admin/css/login.css">
    <!--<script src="js/layui/layui.all.js"></script>-->

    <style>
        .layui-anim-upbit{
            color:black !important;
        }
    </style>
</head>
<body>
<div class="user-login user-display-show" id="user-login">
    <div class="loginForm layui-bg-black" style="position: relative;left: 50%;transform: translateX(-50%);">
        <div class="user-login-main">
            <div class="user-login-box user-login-header">
                <h3>VPN管理系统</h3>
            </div>
            <div class="user-login-header" style="display: none">
                <a style="color:#bff5bc;" href="station.html">（点击切换到联盟商家后台登陆）</a>
            </div>

            <!--<div class="user-login-header">-->
                <!--<a style="color:#bff5bc;" href="http://api.hnxljky.com:7001/index1.html">（点击切换到区域中心后台登陆）</a>-->
            <!--</div>-->

            <!--<div class="user-login-header">-->
                <!--<a style="color:#bff5bc;" href="http://api.hnxljky.com:7001/station1.html">（点击切换到供货商后台登陆）</a>-->
            <!--</div>-->

            <div class="user-login-box user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                           class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input  type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码"
                           class="layui-input">
                </div>

                <!--<select name="city" style="color:black !important;" lay-filter="login">-->
                    <!--<option value="1">特行办登录</option>-->
                    <!--<option value="2">物业登录</option>-->
                <!--</select>-->


                <div class="layui-form-item">
                    <button id="loginBtn" class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
                </div>

            </div>
        </div>
    </div>
    <div class="layui-trans user-login-footer">
        <p>© 2022 <a href="#" target="_blank">VPN后台管理系统</a></p>
    </div>
</div>
<script src="/js/layui/layui.all.js"></script>
<!--<script src="/admin/js/login.js"></script>-->
<script>

    var layer = layui.layer;
    var form = layui.form;
    var login_type = 1 ;
    //得到工程路径
    function getRootPath() {
        //http://localhost:8083/uimcardprj/share/meun.jsp
        var curWwwPath = window.document.location.href;
        //uimcardprj/share/meun.jsp
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
        //http://localhost:8083
        var localhostPaht = curWwwPath.substring(0, pos);
        // uimcardprj
        var projectName = pathName
            .substring(0, pathName.substr(1).indexOf('/') + 1);
        if (projectName == "/admin" || projectName=="/static" || projectName=="/weixin" || projectName=="/business")
            projectName = "";

        return (projectName);
    }
    var path = getRootPath();
    var $ = layui.$;
    $("#loginBtn").click(function () {
        var username = $("#LAY-user-login-username").val();
        var password = $("#LAY-user-login-password").val();
        var code2 = $("#loginCard").val();
        if(username==null||username==''){
            layer.msg("用户名不能为空");
            return;
        }
        if(password==null||password==''){
            layer.msg("密码不能为空");
            return;
        }
        if(login_type == 1) {
            $.ajax({
                url: '/login/adminLogin',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    // console.log(data.data);
                    if(data.code==200){
                        //sessionStorage    会话结束的时候,sessionStorage中的键值对会被清空
                        //localStorage      将第一次请求的数据直接存储到本地，这个相当于一个5M大小的针对于前端页面的数据库，相比于cookie(4K)可以节约带宽，但是这个却是只有在高版本的浏览器中才支持的
                        sessionStorage.setItem("admin_id",data.data.id);
                        sessionStorage.setItem("admin_name",data.data.username);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/main.html";

                                }
                            }
                        );

                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                }
                ,
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }else{
            $.ajax({
                url: '/login/wuye',
                type: 'post',
                data: {
                    username:username,
                    password:password,
                },
                success:function (data) {
                    if(data.code==200){
                        // localStorage.setItem("admin_id_station",data.data.id);
                        layer.msg("登录成功",{
                                time:2000,
                                end:function () {
                                    window.location.href="/admin/wuye.html";
                                }
                            }
                        );

                    }else{
                        layer.msg(data.msg,{time:2000});
                    }
                }
                ,
                erorr:function(){
                    layer.msg("网络异常");
                }
            });
        }
    });

    form.on("select(login)" , function(res) {
        login_type = res.value
    })

    $(window).keypress(function (event) {
        if(event.which === 13){
            $('#loginBtn').click();
        }
    })


</script>
</body>
</html>